package com.cdu.controller;

import com.cdu.pojo.dto.SearchQueryDTO;
import com.cdu.pojo.vo.PageVO;
import com.cdu.pojo.vo.ProductVO;
import com.cdu.service.SearchService;
import com.cdu.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/api/products")
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 根据关键字查询商品
     * @param keyword 搜索关键字
     * @return 商品列表
     */
    @GetMapping("/search")
    public PageVO<ProductVO> searchProducts(@RequestParam String keyword,  @RequestParam int pageNum, @RequestParam int pageSize) {
        SearchQueryDTO queryDTO = new SearchQueryDTO();
        queryDTO.setPageNum(pageNum);
        queryDTO.setPageSize(pageSize);
        return searchService.searchProducts(queryDTO, keyword);
    }
}
